﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Lapkin.Models.DataModels;
using Lapkin.Models.Repositories;
using Ninject;
using WebMatrix.WebData;

namespace Lapkin.Controllers
{
    public class HomeController : Controller
    {
        [DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        private static extern int AllocConsole();

        private readonly SqlRepository _repository = new SqlRepository();

        public ActionResult Index()
        {
            var db = new MainContext();
            return View(db.Categories.ToList());
        }

        [Authorize(Roles = "Admin")]
        public ActionResult RoleAdd()
        {
            return View(new Role());
        }

        [HttpPut]
        public ActionResult RoleAdd(Role newRole)
        {
            if (ModelState.IsValid)
            {
                var db = new MainContext();
                newRole.Id = Guid.NewGuid();
                db.Roles.Add(newRole);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(newRole);
        }

        private void _fiba(int num)
        {

        }
    }
}
